package com.yanchangapp.ui.activity._n_manage;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.yanchangapp.R;
import com.yanchangapp.commom.AppConstant;
import com.yanchangapp.ui.presenter.NotFinishAtPresenter;
import com.yanchangapp.ui.view.NotFinishAtView;
import com.zxl.baselib.baseapp.AppManager;
import com.zxl.baselib.ui.base.BaseActivity;
import com.zxl.baselib.util.ui.UIUtils;
import butterknife.BindView;

/**
 * page: 不能完成计划信息录入界面
 */
public class NotFinishPlanActivity extends BaseActivity<NotFinishAtView, NotFinishAtPresenter> implements NotFinishAtView {

    @BindView(R.id.ivToolbarNavigation)
    ImageView ivToolbarNavigation;
    @BindView(R.id.vToolbarDivision)
    View vToolbarDivision;
    @BindView(R.id.tvToolbarTitle)
    TextView tvToolbarTitle;
    @BindView(R.id.etKeyInput)
    EditText etKeyInput;
    @BindView(R.id.btnEnsure)
    Button btnEnsure;
    private static final String PLAN_ID = "PLAN_ID";
    private long planID;

    public static void show(Activity activity, long planID) {
        Intent intent = new Intent(activity, NotFinishPlanActivity.class);
        intent.putExtra(PLAN_ID, planID);
        activity.startActivityForResult(intent, AppConstant.RECODE_NOT_FINISH_PLAN);
    }

    @Override
    protected void init() {
        planID = getIntent().getLongExtra(PLAN_ID,-1);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_not_finish_work;
    }

    @Override
    protected NotFinishAtPresenter createPresenter() {
        return new NotFinishAtPresenter(this);
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        tvToolbarTitle.setText("不能完成原因");
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {
        ivToolbarNavigation.setOnClickListener(v -> finish());

        btnEnsure.setOnClickListener(v -> {
            String reason = etKeyInput.getText().toString();
            if (TextUtils.isEmpty(reason)){
                UIUtils.showToast("请输入不能完成的原因");
                return;
            }
            mPresenter.cannotFinishPlan(planID,reason);
        });
    }

    @Override
    public void cannotFinishSuccess() {
        mRxManager.post(DailyPlanActivity.CMD_START_WORK,true);
        AppManager.getAppManager().returnToActivity(DailyPlanActivity.class);
    }

    @Override
    public void cannotFinishFailure(String err) {
        UIUtils.showToast(err);
    }
}
